﻿using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using AdonisUI.Controls;
using System.Reflection;

namespace YJTTool.Core.BaseEntity
{
    public class InheritBase : BindableBase
    {
        /// <summary>
        /// 信息提示
        /// </summary>
        /// <param name="msg"></param>
        public void MessgaeInfo(string msg)
        {
            MessageBox.Show(msg, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information);
        }
        /// <summary>
        /// 警告提示
        /// </summary>
        /// <param name="msg"></param>
        public void MessgaeWarning(string msg)
        {
            MessageBox.Show(msg, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
        }
        /// <summary>
        /// 错误提示
        /// </summary>
        /// <param name="msg"></param>
        public void MessgaeError(string msg)
        {
            MessageBox.Show(msg, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Error);
        }
        /// <summary>
        /// 将输入的字符转为大写
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public string ConvertToUpperIfEnglish(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return input;
            }

            bool isEnglish = input.All(c => Char.IsLetter(c) && (Char.IsLower(c) || Char.IsUpper(c)));

            if (isEnglish)
            {
                return input.ToUpper(); 
            }

            return input; 
        }
    }
    public static class StringExtensions
    {
        /// <summary>
        /// 将字符串转换为整数，如果转换失败返回默认值（0）。
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static int ToIndex(this string columnLetter)
        {
            int columnIndex = 0;

            // 遍历列字母的每一位
            foreach (char c in columnLetter.ToUpper())
            {
                // 将每个字母转换为对应的数字并更新列索引
                columnIndex = columnIndex * 26 + (c - 'A' + 1);
            }

            return columnIndex;
        }

    }
}
